package com.css.modules.lawRepo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.css.common.utils.PageUtils;
import com.css.common.utils.Query;
import com.css.modules.lawRepo.dao.LawRepoDocApprovalDao;
import com.css.modules.lawRepo.entity.LawRepoDocApprovalEntity;
import com.css.modules.lawRepo.service.LawRepoDocApprovalService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


@Service
public class LawRepoDocApprovalServiceImpl extends ServiceImpl<LawRepoDocApprovalDao, LawRepoDocApprovalEntity> implements LawRepoDocApprovalService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<LawRepoDocApprovalEntity> page = this.page(
                new Query<LawRepoDocApprovalEntity>().getPage(params),
                new QueryWrapper<LawRepoDocApprovalEntity>()
        );
        return new PageUtils(page);
    }

    @Override
    public void  insert(LawRepoDocApprovalEntity docApprovalEntity) {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        docApprovalEntity.setUuid(uuid);
        docApprovalEntity.setDelFlag("2");
        docApprovalEntity.setStatusNum("2");
        this.save(docApprovalEntity);
    }

    @Override
    public void update(LawRepoDocApprovalEntity docApprovalEntity) {
        this.updateById(docApprovalEntity);
    }

    @Override
    public LawRepoDocApprovalEntity findByDocId(String docId) {
        LawRepoDocApprovalEntity docApprovalEntity= this.baseMapper.findByDocId(docId);
        return docApprovalEntity;
    }

    @Override
    public void updateDelFlagAll(String delFlag) {
        if (StringUtils.isNotBlank(delFlag)) {
            this.baseMapper.updateDelFlagAll(delFlag);
        }
    }

    @Override
    public void commonUpdateDelFlagBatch(String delFlag, Map<String, Object> mapIds){
        Map<String, Object> map = new HashMap<>(2);
        map.put("list", mapIds.get("ids"));
        map.put("delFlag", delFlag);
        baseMapper.commonUpdateDelFlagBatch(map);

    }


}
